﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace SqlPermissionsAuditor
{
    /// <summary>
    /// From http://www.codeproject.com/KB/WPF/OppositeBoolConverter.aspx
    /// </summary>
    public class BoolToOppositeBoolConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter,
            System.Globalization.CultureInfo culture)
        {
            if (targetType != typeof(bool) && targetType != typeof(bool?))
            {
                throw new InvalidOperationException("The target must be a boolean");
            }

            return !(bool?)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter,
            System.Globalization.CultureInfo culture)
        {
            //When this was without the !, the binding was breaking after going back from windows auth
            //to sql auth. I believe it's because it was then settings 'true' on two radio buttons in the same group
            //and probably breaking the binding. its a guess but when adding the !, suddenly I can go back and forth without
            //the issues anymore.
            return !(bool?)value;
            //throw new NotSupportedException();
        }

        #endregion
    }
}
